package com.mlh.service.impl;

import com.mlh.entity.Monster;
import com.mlh.mlhspringmvc.annotation.Service;
import com.mlh.service.MonsterService;

import java.util.ArrayList;
import java.util.List;

@Service
public class MonsterServiceImpl implements MonsterService {
    @Override
    public List<Monster> listMonster() {
        //模拟数据->DB
        List<Monster> monsters = new ArrayList<>();
        monsters. add (new Monster(100,"牛魔王","芭蕉扇",400));
        monsters. add (new Monster(200,"老 猫妖怪","抓老鼠",200));
        return monsters ;
    }

    @Override
    public List<Monster> findMonsterByName(String name) {
        List<Monster> monsters = new ArrayList<>();
        monsters.add(new Monster(100, "牛魔王", "芭蕉扇", 400));
        monsters.add(new Monster(200, " 老猫妖怪", "抓老鼠", 200));
        monsters.add(new Monster(300, "大象精", "运木头", 100));
        monsters.add(new Monster(400, "黄袍怪", "吐烟雾", 300));
        monsters.add(new Monster(500, "白骨精", "美人计", 800));
        // 创建集合返回查询到的monster集合
        List<Monster> findMonsters = new ArrayList<>();
        // 遍历imonsters,返回满足条件
        for (Monster monster : monsters) {
            //contains()是判断调用该方法的字符串是否包含参数中的字符串
            if (monster.getName().contains(name)) {
                findMonsters.add(monster);
            }
        }
        return findMonsters;
    }

    @Override
    public boolean login(String name) {
        //模拟数据库
        if("白骨精".equals(name)){
            return true;
        }else{
            return false;
        }
    }
}
